package thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description: null
 * @Project: testDemo
 * @Author: hjibo
 * @CreateDate: 2019/2/21 18:26
 * @ModificationHistory: （who whatTime doWhat）
 */
public class MainBath {

public static void main(String[] args) {
    // 创建一个线程池
    ExecutorService executor = Executors.newFixedThreadPool(5);
    // 小弟
    CountDownLatch worm = new CountDownLatch(1);
    // 大佬
    CountDownLatch mogul = new CountDownLatch(3);
    try {

//            Runnable worm1 = new ThreadBath("小明",worm,null);
//            Runnable worm2 = new ThreadBath("小强",worm,null);
//            Runnable mogul1 = new ThreadBath("大佬1号",null,mogul);
//            Runnable mogul2 = new ThreadBath("大佬2号",null,mogul);
//            Runnable mogul3 = new ThreadBath("大佬3号",null,mogul);

        executor.execute(new ThreadBath("小明",worm,null));
        executor.execute(new ThreadBath("小强",worm,null));
        executor.execute(new ThreadBath("大佬云云",null,mogul));
        executor.execute(new ThreadBath("大佬腾腾",null,mogul));
        executor.execute(new ThreadBath("大佬林林",null,mogul));

        // 等待大佬们洗澡。。。
        for(;;){
            // 大佬们都洗完澡了
            if(mogul.getCount() == 0){
                // 小弟们可以洗澡了
                worm.countDown();
                // 给小弟们个洗澡时间，届时关闭澡堂
                Thread.sleep(5000);
                break;
            }
        }

        System.out.println("大家都洗完澡了！关闭澡堂！！！");

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        executor.shutdown();
    }
}
}
